package com.gadgets.framework.controller.impl;

import com.gadgets.framework.common.Fm04Constant;
import com.gadgets.framework.common.excep.CannotGetWoodenException;
import com.gadgets.framework.common.util.RedisUtil;
import com.gadgets.framework.controller.IWoodenCustomerController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 功能说明：访问令牌消费访问实现
 *
 * @author Unclexiu
 * @version V202101.00.000
 * @data 2022-07-19
 * 修改记录：  修改日期          修改人员    修改说明
 * 2022-07-19  xiujunqing   创建文件
 */
@RestController
@RequestMapping(value = "/wooden")
public class WoodenCustomerController implements IWoodenCustomerController {

	protected final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private RedisUtil redisUtil;

	/**
	 * 令牌消费
	 * @param request 						网络请求
	 * @param response 						网络应答
	 * @param num							消费数
	 * @throws CannotGetWoodenException    	异常信息
	 */
	@RequestMapping(value = "/customer.do")
	@Override
	public void customerWooden(HttpServletRequest request, HttpServletResponse response, int num) throws CannotGetWoodenException {
		try {
			redisUtil.decreByKey(Fm04Constant.WOODEN_REDIS_KEY, num);
		} catch (Throwable e) {
			throw new CannotGetWoodenException();
		}
	}

}
